﻿///<reference path="_moduleReferences.ts" />

module ScrambledEggs.Modules {
    export class StatusDisplay implements IModule {

        private _onUpdate: () => void;
        private _maxPhysique = 500;
        private _maxIntelligence = 500;

        constructor() {
        }

        initialize(gameState: GameStateProvider, onUpdate: () => void ) {
            this._onUpdate = onUpdate;
        }

        update(gameState: GameStateProvider, triggerSource: IModule): void {
            if (gameState.State.Phase == GamePhase.Fetus) {
                $("#status").hide();
                return;
            }
            $("#primary").show();
            var status = $("#status").show();
            var state = gameState.State;

            status.children("div").hide();
            status.find(".name").html(state.Name);
            switch (state.Phase) {
                case GamePhase.Baby:
                    status.find(".baby").show();
                    var intPct = Math.min(100, Math.floor(state.MentalMaturity / this._maxIntelligence * 1000) / 10);
                    var physPct = Math.min(100, Math.floor(state.PhysicalMaturity / this._maxPhysique * 1000) / 10);
                    status.find(".mental").find(".progress").css("width", intPct + "%");
                    status.find(".physical").find(".progress").css("width", physPct + "%");
                    status.find(".fullness").toggle(state.Fullness >= 0).find(".progress").css("width", Math.floor(state.Fullness * 10) / 10 + "%");
                    break;
                case GamePhase.YoungAdult:
                    status.find(".youngadult").show();
                    status.find(".intelligence").toggle(state.Intelligence > -1).find(".value").html(state.Intelligence);
                    status.find(".popularity").toggle(state.Popularity > -1).find(".value").html(state.Popularity);
                    status.find(".time").toggle(state.Time > -1).find(".value").html(state.Time);
                    status.find(".money").toggle(state.Money > -1).find(".value").html(state.Money);
                    status.find(".job").toggle(state.PartTimeJob != PartTimeJob.None).find(".value").html(Utility.Text.FromJob(state.PartTimeJob, state.Gender));
                    status.find(".energy").find(".progress").css("width", state.Energy + "%");
                    break;
            }
        }        
    }
}